<template>
  <div>
    <el-dialog
      title="监听器参数"
      :visible.sync="dialogVisible"
      width="700px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="true"
      :modal="false"
      @closed="$emit('close', formData.paramList)"
    >
      <x-form ref="xForm" v-model="formData" :config="formConfig" />
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="medium" @click="closeDialog">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixinXcrud from '../../../common/mixinXcrud'
export default {
  mixins: [mixinXcrud],
  props: {
    value: {
      type: Array,
      default: () => []
    },
    maxCodeParam:{
      type:String,
      default:() => ''
    },
  },
  data() {
    return {
      dialogVisible: true,
      formData: {
        paramList: [],
        ysdProcParams:[]
      },
      oldFormData:this.value
    }
  },
  computed: {
    formConfig() {
      /**
       * 初始化页面
       */
      let data = this.value;
      let paramList = [];
      for (let i = 0; i < data.length; i++) {
        console.log(data);
        //优树搭请求参数处理
        if(data[i].name == 'ysdProcParams'){
          this.formData.ysdProcParams = JSON.parse(data[i].value);
        }else{
          //流程其它参数处理
          paramList.push(data[i])
        }
      }
      //赋值其它参数
      this.formData.paramList = paramList;
      return {
        inline: false,
        item: [
          {
            xType: 'tabs',
            tabs: [
              {
                label: '监听器参数',
                name: 'paramList',
                column: [
                  {
                    label: '类型',
                    name: 'type',
                    width: 180,
                    rules: [{ required: true, message: '请选择', trigger: ['blur', 'change'] }],
                    xType: 'select',
                    dic: [
                      { label: '字符串', value: 'stringValue' },
                      { label: '表达式', value: 'expression' }
                    ]
                  },
                  {
                    label: '名称',
                    name: 'name',
                    width: 180,
                    rules: [{ required: true, message: '请选择', trigger: ['blur', 'change'] }],
                    xType: 'input'
                  },
                  {
                    label: '值',
                    name: 'value',
                    xType: 'input',
                    rules: [{ required: true, message: '请输入', trigger: ['blur', 'change'] }]
                  }
                ]
              },
              //优树搭参数配置
              {
                label: '优树搭流程参数',
                name: 'ysdProcParams',
                show: this.maxCodeParam === 'YsdProc',
                column:[
                  {
                    label: '参数类型',
                    name: 'type',
                    width: 180,
                    rules: [{ required: true, message: '请选择', trigger: ['blur', 'change'] }],
                    xType: 'select',
                    dic: [
                      { label: '字符串', value: 'stringValue' },
                      { label: '流程变量', value: 'expression' }
                    ]
                  },
                  {
                    label: '参数名称',
                    name: 'name',
                    width: 180,
                    tooltip: `传入优树搭流程中的参数名称`,
                    rules: [{ required: true, message: '请选择', trigger: ['blur', 'change'] }],
                    xType: 'input'
                  },
                  {
                    label: '参数值',
                    name: 'value',
                    xType: 'input',
                    tooltip:`参数类型为字符串时，会将输入值传入优树搭流程中<br/>
                             参数类型为流程变量时，会根据输入值在流程变量中取出相应数据传入优树搭流程中`,
                    rules: [{ required: true, message: '请输入', trigger: ['blur', 'change'] }]
                  }
                ]
              }
            ]
          }
        ]
      }
    }
  },
  methods: {
    closeDialog() {
      this.formData.paramList.push({'type':'stringValue','name':'ysdProcParams','value':JSON.stringify(this.formData.ysdProcParams)});
      this.$refs.xForm.validate().then(() => {
        this.dialogVisible = false
      }).catch(e => console.error(e))
    }
  }
}
</script>

<style>
.flow-containers .el-badge__content.is-fixed {
  top: 18px;
}
</style>
